package com.example.animationmodule.drawable

import android.content.Context
import android.graphics.Color
import android.graphics.Outline
import android.graphics.RectF
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.OvalShape
import android.graphics.drawable.shapes.RoundRectShape
import com.alibaba.android.arouter.facade.annotation.Route
import com.android.baselibrary.base.BaseActivity
import com.android.baselibrary.utils.ScreenUtils
import com.android.baselibrary.utils.dp2px
import com.example.animationmodule.AnimationPath
import com.example.animationmodule.R
import com.example.animationmodule.databinding.ActivityCustomDrawableBinding

/**
 * @author: Mr.You
 * @create: 2023-02-23 11:00
 * @description:
 **/
@Route(path = AnimationPath.CustomDrawableView)
class CustomDrawableActivity : BaseActivity<ActivityCustomDrawableBinding>() {
    override fun getLayoutId(): Int = R.layout.activity_custom_drawable

    override fun initView() {
        //实心圆
        val drawable = ShapeDrawable(OvalShape())
        drawable.paint.color = Color.RED
        mBinding.tvOval.background = drawable
        //上半边圆角矩形
        val externalRound = floatArrayOf(10f, 10f, 0f, 0f, 0f, 0f, 0f, 0f)
        val shapeDrawable = ShapeDrawable(
            RoundRectShape(
                externalRound,
                RectF(0f, 0f, 0f, 0f),
                floatArrayOf(0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f)
            )
        )
        shapeDrawable.paint.color = Color.BLUE
        mBinding.tvOval2.background = shapeDrawable

        val roundIn = dp2px(this, 30)
        val externalRounds = floatArrayOf(roundIn, roundIn, roundIn, roundIn, roundIn, roundIn, roundIn, roundIn)
        val outlineRound = floatArrayOf(roundIn, roundIn, roundIn, roundIn, roundIn, roundIn, roundIn, roundIn)
        val rectF = RectF(dp2px(this, 2), dp2px(this, 2), dp2px(this, 2), dp2px(this, 2))
        val drawable1 = ShapeDrawable(RoundRectShape(externalRounds, rectF, outlineRound))
        drawable1.paint.color = Color.RED
        mBinding.tvOval3.background = drawable1

        val gradientDrawable = GradientDrawable()
        gradientDrawable.setStroke(dp2px(this, 2).toInt(), Color.RED)
        gradientDrawable.setColor(Color.YELLOW)
        gradientDrawable.shape = GradientDrawable.RECTANGLE
        mBinding.tvOval4.background = gradientDrawable

        val gradientDrawable1 = GradientDrawable()
        gradientDrawable1.setStroke(dp2px(this, 2).toInt(), Color.RED)
        gradientDrawable1.setColor(Color.BLUE)
        gradientDrawable1.shape = GradientDrawable.RECTANGLE
        gradientDrawable1.cornerRadius = roundIn
        mBinding.tvOval5.background = gradientDrawable1

        val gradientDrawable2 = GradientDrawable()
        gradientDrawable2.setStroke(dp2px(this, 2).toInt(), Color.RED)
        gradientDrawable2.setColor(Color.GREEN)
        gradientDrawable2.shape = GradientDrawable.OVAL
        mBinding.tvOval6.background = gradientDrawable2
    }

    override fun initListener() {

    }

    fun dp2px(context: Context, dp: Int): Float = (context.resources.displayMetrics.density * dp + 0.5).toFloat()
}